package cn.net.xinyi.xs.model.system;

import java.io.Serializable;

import javax.persistence.Transient;

import cn.net.xinyi.xs.model.BaseObject;

public class UserRight extends BaseObject implements Serializable {
	private static final long serialVersionUID = -745374629449910168L;

	// �����
	public static final int USERRIGHT_CONTROL_VIEW = 1;

	// ������
	public static final int USERRIGHT_CONTROL_ADD = 2;

	// �����
	public static final int USERRIGHT_CONTROL_MODIFY = 3;

	// ����ɾ
	public static final int USERRIGHT_CONTROL_DELETE = 4;

	private Long parentId;

	private Long roleId;

	private String roleName;

	private Long rightId;

	private String type;

	private Integer userGrade;

	private Boolean isDefault;

	private String url;

	private String moduleName;

	private String menuName;

	private Boolean rightMode;

	private String control;

	public Long getParentId() {
		return parentId;
	}

	public void setParentId(Long parentId) {
		this.parentId = parentId;
	}

	public Long getRoleId() {
		return roleId;
	}

	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}

	@Transient
	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public Long getRightId() {
		return rightId;
	}

	public void setRightId(Long rightId) {
		this.rightId = rightId;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Integer getUserGrade() {
		return userGrade;
	}

	public void setUserGrade(Integer userGrade) {
		this.userGrade = userGrade;
	}

	public Boolean getIsDefault() {
		return isDefault;
	}

	public void setIsDefault(Boolean isDefault) {
		this.isDefault = isDefault;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

	public String getMenuName() {
		return menuName;
	}

	public void setMenuName(String menuName) {
		this.menuName = menuName;
	}

	public Boolean getRightMode() {
		return rightMode;
	}

	public void setRightMode(Boolean rightMode) {
		this.rightMode = rightMode;
	}

	public String getControl() {
		return control;
	}

	public void setControl(String control) {
		this.control = control;
	}

	public UserRight merge(UserRight p) {
		boolean viewPermit = viewPermit() || p.viewPermit();
		boolean addPermit = addPermit() || p.addPermit();
		boolean editPermit = editPermit() || p.editPermit();
		boolean deletePermit = deletePermit() || p.deletePermit();

		setControl(new StringBuffer().append(viewPermit ? 1 : 0).append(
				addPermit ? 1 : 0).append(editPermit ? 1 : 0).append(
				deletePermit ? 1 : 0).toString());
		return this;
	}

	// �Ƿ�����鿴����
	public boolean viewPermit() {
		return control.charAt(USERRIGHT_CONTROL_VIEW - 1) == '1';
	}

	// �Ƿ������������
	public boolean addPermit() {
		return control.charAt(USERRIGHT_CONTROL_ADD - 1) == '1';
	}

	// �Ƿ�����༭����
	public boolean editPermit() {
		return control.charAt(USERRIGHT_CONTROL_MODIFY - 1) == '1';
	}

	// �Ƿ�����ɾ�����
	public boolean deletePermit() {
		return control.charAt(USERRIGHT_CONTROL_DELETE - 1) == '1';
	}

	@Override
	public boolean equals(Object o) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public int hashCode() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return null;
	}

}
